package com.whfc.ms.api.sys.controller;


import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.FaceCheckInResultDTO;
import com.whfc.entity.dto.Apply.rep.ClassMeetingInfoRep;
import com.whfc.entity.dto.Apply.rep.StaffInfoRep;
import com.whfc.entity.dto.Apply.req.*;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.ms.api.sys.dto.FaceCheckInReq;
import com.whfc.ms.api.sys.service.SysApplyService;
import com.whfc.ms.api.sys.service.SysClassMeetingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @author xjy
 * @description 谢江泳
 * @date 2025-09-18
 * 班会
 */
@RestController
@RequestMapping("/mp/api/classMeeting")
public class SysClassMeetingController {

    @Autowired
    private SysClassMeetingService classMeetingService;
    @Autowired
    private SysApplyService wxApplyService;


    /**
     * 获取班会列表支持分页
     * @return
     */
    @GetMapping("/list")
    public Result list(AppEntryApplicationReq req) {
        PageData<MeetingDto> meetingList = classMeetingService.list(req);
        return ResultUtil.success(meetingList);
    }

    /**
     * 创建班会
     *
     * @return 描述申请操作响应的字符串
     */
    @PostMapping("/saveClassMeeting")
    public Result saveClassMeeting(@SessionAttribute(SessionAttr.MS_USER) SysUser sysUser, @RequestBody ClassMeetingCreateReq req) {
        String msg = classMeetingService.saveClassMeeting(sysUser, req);
        if(!Objects.equals(msg, "创建班会成功")){
            return ResultUtil.failure();
        }
        return ResultUtil.success();
    }




    /**
     * 获取计划
     * @return
     */
    @GetMapping("/queryEntryerId")
    public Result queryEntryerId(@SessionAttribute(SessionAttr.MS_USER) SysUser sysUser, @RequestParam("id")  Integer id) {
        if(sysUser.getId()==null){
            return ResultUtil.failure("当前用户未登录,请重新登录!");
        }
        return ResultUtil.success(classMeetingService.selectAppWorkPlanList(sysUser,id));
    }

    /**
     * 根据人员姓名查找人员
     *
     * @param req
     * @return
     */
    @PostMapping("/queryEntryerId")
    public Result queryEntryerId(@RequestBody QueryPersonnelReq req) {
        List<SafetyTrainingExamReq> examReqList = wxApplyService.queryPersonnel(req);
        return ResultUtil.success(examReqList);
    }

    /**
     * 根据Id查询班会
     * @return
     */
    @GetMapping("/queryMeeting")
    public Result queryMeeting(@RequestParam("id")  Integer id) {
        ClassMeetingInfoRep classMeeting = classMeetingService.queryMeeting(id);
        return ResultUtil.success(classMeeting);
    }

    /**
     * 签到
     * @return
     */
    @PostMapping("/checkIn")
    public Result checkIn(@SessionAttribute(SessionAttr.MS_USER) SysUser sysUser, @RequestBody FaceCheckInReq req) {
        FaceCheckInResultDTO data = classMeetingService.faceCheckIn(sysUser, req);
        return ResultUtil.success(data);
    }

    /**
     * 添加文件地址
     * @return
     */
    @GetMapping("/addFilePath")
    public Result addFilePath(@RequestParam("id")  Integer id,@RequestParam("filePath")  String filePath) {
        String msg = classMeetingService.addFilePath(id,filePath);
        if(msg != null && Objects.equals(msg,"1")){
            return ResultUtil.success("文件上传成功");
        }
        return ResultUtil.failure("文件上传失败");

    }

    @GetMapping("/querycheckInList")
    public Result querycheckInList(@RequestParam("id" )  Integer id) {
        List<StaffInfoRep> examReqList = classMeetingService.querycheckInList(id);
        return ResultUtil.success(examReqList);
    }

}
